package com.kaishengit.web;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.kaishengit.dao.ProjectDao;
import com.kaishengit.dao.TaskDao;
import com.kaishengit.entity.Project;
import com.kaishengit.entity.Task;
import com.kaishengit.entity.User;

public class ProjectServlet extends HttpServlet {

	
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		HttpSession session = request.getSession(); 
		User user = (User)session.getAttribute("user");
		int id = Integer.parseInt(request.getParameter("projectid"));
		Project p = new Project();
		ProjectDao pdao = new ProjectDao();
		p = pdao.findByProjectId(id);
		TaskDao tdao = new TaskDao();
		List<Task> tlist = new ArrayList<Task>(); 
		tlist = tdao.findByID(id, user.getId());
		request.setAttribute("project", p);
		request.setAttribute("tlist", tlist);
		RequestDispatcher rd= request.getRequestDispatcher("WEB-INF/views/project.jsp");
		rd.forward(request, response);
	}

}
